<template>
	<view class="goods-detail shangpin">
		<block v-if="goods!=''">
		<u-swiper imgMode="heightFix" :list="goods_imgs" @change="e => current = e.current" :autoplay="false" height="700rpx" keyName="image_url">
			<view slot="indicator" class="indicator">
				<view class="indicator__dot" v-for="(item, index) in goods_imgs" :key="index"
					:class="[index === current && 'indicator__dot--active']">
				</view>
			</view>
		</u-swiper>
		<view class="goods-container">
			<view class="goods-top">
				<view class="goods-price">
					<view class="left">
						<text class="price">{{goods.goods_price}}</text>
						<text>/{{goods.name}}</text>
					</view>
				</view>
				<view class="goods-name">{{goods.goods_name}}</view>
				<view class="goods-remark" v-if="goods.goods_remark">{{goods.goods_remark}}</view>
			</view>
		</view>
		<view class="shop-goods-xq">
			<view class="title">
				<text class="line"></text>
				<text class="xq-tit">商品详情</text>
				<text class="line"></text>
			</view>
			<view v-html="goods.goods_content" class="goods-content"></view>
		</view>
		<view style="height: 120rpx;background: none;margin-top: 0;"></view>
		<view class="goods-bot">
			<view class="left">
				<view class="left-item" @tap='goIndex()'>
					<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/goods/goods-sy.png" mode="widthFix"></image>
					<view class="text">首页</view>
				</view>
				<view class="left-item">
					<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/goods/goods-kf.png" mode="widthFix"></image>
					<view class="text">客服</view>
				</view>
			</view>
			<view class="right">
				<button class="buy-now" @click="buy_now">立即兑换</button>
			</view>
		</view>
		</block>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				goods_imgs: [],
				current: 0,
				goods: '',
				id:0,
			}
		},
		onLoad(e) {
			_this=this
			this.id = e.id
			if(this.id==undefined){
				uni.$u.toast("提交参数有误")
				setTimeout(()=>{
					uni.navigateBack({})
				},2000)
			}
			this.getgoods()
		},
		onShareAppMessage() {
			if(_this.goods!=''){
				return {
					title:_this.goods.goods_name,
					path:'/pages/cart/show?reid='+_this.user_id+'&id='+_this.goods.goods_id,
					imageUrl:_this.goods.goods_img
				}
			}
		},
		methods: {
			//获取商品信息
			async getgoods() {
				const params = {
					id: _this.id,
				}
				const data = await _this.$post('api/dh_goods_xq',params)
				if(data.code==200){
					this.goods_imgs = data.data.goods_imgs
					this.goods = data.data.goods
				}else{
					uni.$u.toast(data.msg)
					setTimeout(()=>{
						uni.navigateBack({})
					},2000)
				}
			},
			buy_now(){
				uni.navigateTo({
					url:`/pages/order/dh-order-confirm?id=${_this.id}`
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
	@import "@/static/css/goods.scss";
</style>